# -*- coding: utf-8 -*-
import logging
from odoo import models, fields, api, _

_logger = logging.getLogger(__name__)
# PAC1020000142008

class ZfyStockQuant(models.Model):
    _inherit = "stock.quant"

    ref = fields.Char(u'追踪号',related='lot_id.ref',store=True)
    product_uom_id = fields.Many2one(
        'product.uom', string='Unit of Measure', related='product_id.uom_id',
        readonly=True,store=True)

    aux_uom_id = fields.Many2one('product.uom', u'辅助单位',
                              related='product_id.product_tmpl_id.aux_uom_id', store=True)
    aux_radio = fields.Float(u'换算率',  digits=(16, 4),
                              related='product_id.product_tmpl_id.aux_radio', store=True)
    def _get_aux_qty(self):
        for rcd in self:
            if rcd.aux_radio!=0:
                rcd.aux_qty = rcd.qty / rcd.aux_radio
    aux_qty = fields.Float(string=u"辅助数量",compute = '_get_aux_qty')
    # @api.multi
    # def get_aux_radio(self):
    #     for rcd in self:
    #         rcd.aux_radio = rcd.product_id.product_tmpl_id.aux_radio
    #         print rcd.product_id.product_tmpl_id.aux_uom
    #         print rcd.product_id.aux_uom
    # aux_radio = fields.Float(u'换算率', digits=(16, 4), default=get_aux_radio,store=True)
